<%@ tag body-content="empty" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="cf" uri="http://kyub.com/jsp/jstl/functions" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ attribute name="pojoDescriptor" required="true" type="com.kyub.spring.gears.model.PojoDescriptor" %>
<%@ attribute name="pojo" required="true" type="java.lang.Object" %>
<%@ attribute name="gears_restfull_prefix" required="true" %>
<h2>${pojoDescriptor.name}</h2>

<p><c:if test="${not empty pageContext.request.parameterMap.backPojo[0]}">
    <c:set var="back_pojo_param" value="?backPojo=${pageContext.request.parameterMap.backPojo[0]}"/>
</c:if>
    <span >
        <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/list/${back_pojo_param}">Back to list</a>
    </span>
    <span>
    <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/update/${cf:readProperty(pojo,pojoDescriptor.idProperty)}${back_pojo_param}">Edit</a>
    </span>
</p>
 <div class="ui-corner-all">
<table>

    <c:forEach items="${pojoDescriptor.properties}" var="p">
        <tr>
            <td>${p.name}:</td>
            <td>

                <c:if test="${cf:isSimpleProperty(p)}">
                   <c:choose>
                                <c:when test="${cf:readProperty(pojo,p.name).class.simpleName == 'Date'}">
                                    <fmt:formatDate value="${cf:readProperty(pojo,p.name)}"/>
                                </c:when>
                                <c:when test="${cf:readProperty(pojo,p.name).class.simpleName == 'Boolean'}">
                                      <c:choose>
                                            <c:when test="${cf:readProperty(pojo,p.name)}">
                                                <span class="ui-icon ui-icon-check"></span>
                                           </c:when>
                                            <c:otherwise>
                                                <span class="ui-icon ui-icon-closethick"></span>
                                            </c:otherwise>
                                            </c:choose>
                                </c:when>
                                <c:otherwise>
                                    ${cf:readProperty(pojo,p.name)}
                                </c:otherwise>
                            </c:choose>
                </c:if>
                <c:if test="${cf:isRelation(p)}">
                    <c:if test="${not empty p.pojoDescr}">
                        <a href="#"
                            onclick="openDisplayDialog('${pageContext.request.contextPath}/${gears_restfull_prefix}/${p.pojoDescr.name}/riaview/${cf:readProperty(cf:readProperty(pojo,p.name),p.pojoDescr.idProperty)}?backPojo=${pojoDescriptor.name}')"
                           > ${cf:readProperty(pojo,p.name)}</a>
                    </c:if>
                    <c:if test="${empty p.pojoDescr}">
                        ${cf:readProperty(pojo,p.name)}
                    </c:if>
                </c:if>
                <c:if test="${cf:isCollection(p)}">
                    <a onclick="openDisplayDialog('${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/riaviewrelated/${cf:readProperty(pojo,pojoDescriptor.idProperty)}/${p.name}?backPojo=${pojoDescriptor.name}')"
                       href="#">${p.name} </a>
                </c:if>
                <c:if test="${cf:isFile(p)}">
                    <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/download/${cf:readProperty(commandPojo,pojoDescriptor.idProperty)}/${p.name}">
                        <spring:message code="${pojoDescriptor.name}.labelDownload" text="Download"
                                        htmlEscape="true"/>

                    </a>
                </c:if>

            </td>
        </tr>
    </c:forEach>
</table>
</div>
